<template>
	<view>
		<view class="top_bar">
			<uni-nav-bar color="#ffffff" background-color="#00aded" :status-bar="true" left-icon="left" left-text="返回" title="修改密码" @clickLeft="back" fixed="true" />
			<uni-notice-bar showIcon single="true" text="请记住修改后的密码,找回密码需联系系统管理员" scrollable="true"></uni-notice-bar>
		</view>
		<view class="updatePdw">
			<form @submit="formSubmit">
				<view class="uni-form-item uni-column">
					<view class="title">原密码</view>
					<input class="uni-input" name="prepassword" placeholder="请输入原密码" password="true" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">新密码</view>
					<input class="uni-input" name="newpassword" placeholder="请输入新密码" password="true" />
				</view>
				<view class="uni-form-item uni-column">
					<view class="title">确认新密码</view>
					<input class="uni-input" name="againNewpassword" placeholder="确认密码" password="true" />
				</view>
				<view class="uni-btn-v">
					<button form-type="submit" type="primary" size="default">确认修改</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			formData: {
				password1: '',
				password2: '',
				password3: ''
			}
		};
	},
	methods: {
		back() {
			// #ifdef APP-PLUS
			uni.navigateBack();
			// #endif

			// #ifdef H5
			this.$router.back();
			// #endif
		},
		submitForm() {
			console.log(this.formData);
		},
		async formSubmit(e) {
			var formdata = e.detail.value;
			if (formdata.newpassword != formdata.againNewpassword) {
				uni.showModal({
					content: '两次新密码不一致',
					showCancel: false
				});
				return;
			} else {
				formdata.userid = uni.getStorageSync('userId');
				const res = await this.$myRequest({
					url: '/icore.icp.web/pass/v1/sysusers/updpsw',
					method: 'POST',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: formdata
				}).catch((err) => {
					uni.showToast({
						duration: 2000,
						title: err,
						icon: 'error'
					});
				});
				if (res.data.code == 0) {
					uni.setStorage({
						key: 'passWord',
						data: formdata.againNewpassword
					});
					uni.showToast({
						title: '修改成功',
						icon: 'success',
						duration: 2000
					});
					setTimeout(() => {
						uni.redirectTo({
							url: '/pages/login/login'
						});
					}, 2000);
				} else {
					uni.showToast({
						title: res.data.message,
						icon: 'none',
						duration: 2000
					});
				}
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.updatePdw {
	.uni-form-item {
		margin-top: 20rpx;
		margin-left: 20rpx;
		font-size: 40rpx;
		font-weight: 500;

		.title {
			color: #dd524d;
			margin-bottom: 20rpx;
		}

		.uni-input {
			border-bottom: 1px solid #55ffff;
		}
	}

	.uni-btn-v {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 30%;
		margin-top: 80rpx;
		width: 300rpx;
		height: 40rpx;
		font-weight: 500;
	}
}
</style>
